package com.yn.pet.controller.app;

import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.controller.app.biz.AppUserBizService;
import com.yn.pet.controller.pc.response.AppUserInfoResponse;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/front/app/user")
public class AppUserController {

    private final AppUserBizService appUserBizService;

    /**
     * 获取小程序 openId
     * @param wxCode 微信 code
     * @return openId
     */
    @GetMapping("/getWxOpenIdByWxCode")
    public AjaxResult getWxOpenIdByWxCode(@RequestParam String wxCode) {
        return appUserBizService.getMiniOpenIdByWxCode(wxCode);
    }

    @GetMapping("/getUserPhoneByCode")
    public AjaxResult getUserPhoneByCode(@RequestParam String code,@RequestParam String encryptedData,@RequestParam String ivStr){
        return appUserBizService.getUserPhoneByCode(code,encryptedData,ivStr);
    }

    /**
     * 获取用户信息
     * @return 用户信息
     */
    @GetMapping("/getUserInfo")
    @ApiOperation("获取用户基本信息")
    public AjaxResult getUserInfo(){
        AppUserInfoResponse response = appUserBizService.getUserInfo();
        return AjaxResult.success(response);
    }
}
